﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="false"
    CodeFile="ResetPasswordlist.aspx.cs" Inherits="Training.Web.Lists.Administration.UserManagement.ResetPasswordlist" %>

<asp:Content ID="ctnBody" ContentPlaceHolderID="body" runat="server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveUrl("~/scripts/helper.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.msgBox.v1.js") %>" type="text/javascript"></script>
    <div class="page-full-width cf">
        <div class="content-module">
           <%-- <div class="content-module-heading cf">
                <h3 class="fl">
                    Reset Password</h3>
                <span class="fr expand-collapse-text">Click to collapse</span> <span class="fr expand-collapse-text initial-expand">
                    Click to expand</span>
            </div>--%>
            <!-- end content-module-heading -->
            <div class="content-module-main">
                <div>
                    <button id="btnEdit" type="button" onclick="OpenForm('edit');">
                        Reset Password</button>
                </div>
                <br />
                <div style="overflow: auto; height: 350px;">
                    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
                    </table>
                    <div id="pager" class="scroll">
                    </div>
                    <br />
                    <div id="dialog" title="Default dialog">
                    </div>
                </div>
            </div>
            <!-- end content-module-main -->
        </div>
    </div>
    <asp:HiddenField ID="HfStatus" runat="server" />
    <script type="text/javascript">


        $("#btnEdit").button({ icons: { primary: "ui-icon-gear"} });
     

    </script>
    <script type="text/javascript">

        var handlerUrl = '<%= ResolveUrl("~/ajaxhandler/administration/usermanagement/sUserhandler.ashx") %>';

        $('#table').jqGrid({
            url: handlerUrl + '?method=getdata',
            datatype: 'json',

            colNames: ['ID', 'Kode User', 'NIK', 'Nama User', 'Cabang', 'Lokasi', 'Aktif', 'Role'],
            colModel: [
           		{ name: 'UserID', key: true, hidden: true, index: 'USERID', width: 60 },
                { name: 'UserCode', index: 'USERCODE', width: 200, searchoptions: { sopt: ['cn', 'eq']} },
                { name: 'NIK', index: 'NIK', width: 100, searchoptions: { sopt: ['cn', 'eq']} },
           		{ name: 'UserName', index: 'USERNAME', width: 150, searchoptions: { sopt: ['cn', 'eq']} },
                { name: 'Cabang.NamaCabang', index: 'B.NamaCabang', width: 200, searchoptions: { sopt: ['cn', 'eq']} },
           		{ name: 'Lokasi.NamaLokasi', index: 'Lokasi.NamaLokas', width: 200, searchoptions: { sopt: ['cn', 'eq']} },
           		{ name: 'IsActive', index: 'ISACTIVE', width: 100, searchoptions: { sopt: ['eq'] }, align: 'Center', formatter: 'checkbox', formatoptions: { disabled: true} },
                { name: 'role', index: 'ROLE', align: 'center', search: false, sortable: false, width: 100 },

           	],
            rownumbers: true,
            rowNum: 10,
            id: 'UserID',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'USERNAME',
            sortorder: "asc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 'auto',
            height: '100%',
            caption: 'User',
            ajaxGridOptions: { cache: false },
            ondblClickRow: function () {
                OpenForm('edit');
            },
            gridComplete: function () {
                var ids = $('#table').jqGrid('getDataIDs');
                for (var i = 0; i < ids.length; i++) {
                    var _id = $('#table').jqGrid('getCell', ids[i], 'UserID');
                    var _name = $('#table').jqGrid('getCell', ids[i], 'UserName');
                    var _debtorid = $('#table').jqGrid('getCell', ids[i], 'DebtorID');
                    idx = "<a href='javascript:void(0);' class='dialog_link ui-corner-all' title='User Role' onclick=\"onclickButtonRole('" + _id + "', '" + _name + " ');\"><span class='ui-icon ui-icon-newwin'></span>...</a>";
                    sectorId = "<a href='javascript:void(0);' class='dialog_link ui-corner-all' title='Sektor' onclick=\"onclickButtonSector('" + _id + "', '" + _name + " ', '" + _debtorid + "');\"><span class='ui-icon ui-icon-newwin'></span>...</a>";

                    $('#table').jqGrid('setRowData', ids[i], { role: idx, sector: sectorId });
                }
            }
        });

        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: false, closeAfterSearch: true });





        function onclickButtonRole(id, name) {
            $('#table').jqGrid('resetSelection');

            var urlList = '<%= ResolveUrl("~/lists/administration/usermanagement/sUserRolelist.aspx") %>';
            $('#dialog').load(urlList + '?' + 'method=getdata&UserID=' + id + '&menuId=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: false, width: 530, height: 430, title: 'Role untuk ' + name });
            $('#dialog').dialog('open');
        }



        function OpenForm(ctl) {

            var formUrl = '<%= ResolveUrl("~/forms/administration/usermanagement/sUserform.aspx") %>';

            var grid = $('#table');
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'UserID'));
            });

            if (ctl == 'edit') {
                if (selIds.length == 0) {
                    //alert('Pilih data yang mau di reset password !');
                    $.msgBox("Pilih data yang mau di reset password !", null, { title: "Pesan" });
                }

                else {

                    $.msgBox.confirm("Benar data akan di reset password ?", function () {
                        var objUser = new Object();
                        objUser.ID = encodeURIComponent(selText);
                        jsonData = JSON.stringify(objUser);
                        CallAjax('<%= ResolveUrl("~/ajaxhandler/Administration/UserManagement/sUserhandler.ashx") %>', "?method=resetpassword", jsonData);
                        setTimeout("$('#table').trigger('reloadGrid');", 3000);
                    }, false);

                }
            }


        }
    
    </script>
</asp:Content>
